package com.wsoft;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.encoders.Hex;

import java.security.SecureRandom;
import java.security.Security;

/**
 * @Author Zhang gukai
 * @Date 2024/11/11 14:07
 */
public class SM1KeyGenerator {
    static {
        Security.addProvider(new BouncyCastleProvider());
    }

    public static String generateSM1Key() {
        // SM1 密钥长度为 128 位（16 字节）
        byte[] key = new byte[16];
        SecureRandom random = new SecureRandom();
        random.nextBytes(key);
        return Hex.toHexString(key);
    }

    public static void main(String[] args) {
        String sm1Key = generateSM1Key();
        System.out.println("Generated SM1 Key: " + sm1Key);
    }
}
